package io.renren.sf.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.renren.sf.dao.FrontUserListDao;
import io.renren.sf.entity.CampusEntity;
import io.renren.sf.entity.TeacherEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.annotation.AccessType;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import io.renren.sf.dao.FrontUserDao;
import io.renren.sf.entity.FrontUserEntity;
import io.renren.sf.service.FrontUserService;
import org.springframework.util.StringUtils;


@Service("frontUserService")
public class FrontUserServiceImpl extends ServiceImpl<FrontUserDao, FrontUserEntity> implements FrontUserService {

    @Autowired
    private FrontUserListDao frontUserListDao;

    @Override
    public Page<TeacherEntity> selectFrontUserEntityPage(Map<String, Object> params) {
        String campusId = (String) params.get("campusId");
        String username = (String) params.get("username");
        String userType = (String) params.get("userType");
        long page = Long.parseLong((String) params.get("page"));
        long limit = Long.parseLong((String) params.get("limit"));
        Page<TeacherEntity> userPage = new Page<>(page, limit);
        QueryWrapper<TeacherEntity> queryWrapper = new QueryWrapper<>();
        if(!StringUtils.isEmpty(campusId)){
            queryWrapper.eq("sfu.campus_id",Long.parseLong(campusId));
        }
        if(!StringUtils.isEmpty(username)){
            queryWrapper.like("sfu.mobile",username);
        }
        if(!StringUtils.isEmpty(userType)){
            queryWrapper.eq("sfu.user_type",Integer.parseInt(userType));
        }
        frontUserListDao.selectFrontUserEntityPage(userPage,queryWrapper);
        return userPage;
    }

    @Override
    public List<Map<String,Object>> getMacAddress(Long userId) {
        return baseMapper.getMacAddress(userId);
    }
}